using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Konst3d.Efficiency.Suite;

namespace PEM
{
	/// <summary>
	/// Interaction logic for CreateEditTaskDialog.xaml
	/// </summary>
	public partial class CreateEditTaskDialog : PersistentModalDialog
	{
		public string TaskTitle
		{
			get
			{
				return uiTaskTitleTextBox.Text;
			}
		}

		public string TaskDescription
		{
			get
			{
				return uiTaskDescriptionTextBox.Text;
			}
		}

		public TaskSeverity TaskSeverity
		{
			get
			{
				return _severity[uiTaskSeverityComboBox.SelectedIndex >= 0 ? uiTaskSeverityComboBox.SelectedIndex : 0];
			}
		}

		public DateTime TaskDeadLine
		{
			get
			{
				return uiTaskDeadLineDatePicker.SelectedDate ?? DateTime.Now.AddDays(1); // TOFIX: validation instead of this crap
			}
		}

		public CreateEditTaskDialog()
		{
			InitializeComponent();
		}

		public bool ShowDialog(Window owner, ITask task)
		{
			if (task != null)
			{
				uiTaskTitleTextBox.Text = task.Title;
				uiTaskDeadLineDatePicker.SelectedDate = task.DeadLine;
				uiTaskSeverityComboBox.SelectedIndex = (int)task.Severity;
				uiTaskDescriptionTextBox.Text = task.Description;
			}
			else
			{
				uiTaskTitleTextBox.Text = String.Empty;
				uiTaskDeadLineDatePicker.SelectedDate = DateTime.Now.AddDays(1);
				uiTaskSeverityComboBox.SelectedIndex = 0;
				uiTaskDescriptionTextBox.Text = String.Empty;
			}

			return ShowDialog(owner);
		}

		private void OnCreateButtonClick(object sender, RoutedEventArgs e)
		{
			DialogResult = true;
		}

		private void OnCancelButtonClick(object sender, RoutedEventArgs e)
		{
			DialogResult = false;
		}

		#region Fields

		private static readonly TaskSeverity[] _severity = new TaskSeverity[] { TaskSeverity.Low, TaskSeverity.Normal, TaskSeverity.Hight, TaskSeverity.Critical };

		#endregion // Fields
	}
}
